package com.hmy.singleton;

/**
 * 单例模式：确保一个类只有一个实例，并且提供全局的访问点
 *
 */
public class Singleton6 {
	private static Singleton6 uniqueSingleton;
	
	//构造器私有化
	private Singleton6() {
		
	}
	//延迟实例化，只适合单线程
	public static Singleton6 getSingletonInstance() {
		return SingletonHolder.INSTANCE.getInstance();
	}
	//利用枚举类实现单例，jvm会保证线程安全
	private static enum SingletonHolder {
		INSTANCE;
		private Singleton6 singleton6;
		private SingletonHolder() {
			singleton6 = new Singleton6();
		}
		public Singleton6 getInstance() {
			return singleton6;
		}
		
	}
	
}
